package com.vietnam.power.domain;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.springframework.context.i18n.LocaleContextHolder;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class Transaction {

	private Set<Product> products;
	private PatronInfo patronInfo;
	private BigDecimal totalPrice;
	private String paymentMethodName;
	private String transactionRefNum;
	private int id;
	private Date createdDate;
	private int orderStatus;
	private String remark;

	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

	public void addProducts(Product product) {
		if (this.products == null) {
			this.products = new HashSet<Product>();
		}

		this.products.add(product);
	}

	public PatronInfo getPatronInfo() {
		return patronInfo;
	}

	public void setPatronInfo(PatronInfo patronInfo) {
		this.patronInfo = patronInfo;
	}

	@JsonIgnore
	public String getTotalPriceAsSale() {
		NumberFormat nf = NumberFormat.getCurrencyInstance(LocaleContextHolder.getLocale());
		nf.setMaximumFractionDigits(0);
		return nf.format(getTotalPrice());
	}

	@JsonIgnore
	public BigDecimal getTotalPrice() {
		this.totalPrice = new BigDecimal(0);
		for (Product p : products) {
			this.totalPrice = this.totalPrice.add(p.getTotalPrice());
		}
		return this.totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}

	public String getPaymentMethodName() {
		return paymentMethodName;
	}

	public void setPaymentMethodName(String paymentMethodName) {
		this.paymentMethodName = paymentMethodName;
	}

	public String getTransactionRefNum() {
		return transactionRefNum;
	}

	public void setTransactionRefNum(String transactionRefNum) {
		this.transactionRefNum = transactionRefNum;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public int getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(int orderStatus) {
		this.orderStatus = orderStatus;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
